import { Settings } from './../../providers/settings';
import { AccountService } from './../../providers/account-service';
import { HttpService } from './../../helper/http';
import { AlertController, App, Events } from 'ionic-angular';
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

/*
  Generated class for the Login page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
  providers:[HttpService,AccountService,Settings]
})
export class LoginPage {
  disNo:string="";
  pwd:string="";
  constructor(public navCtrl: NavController, 
  public navParams: NavParams,
  private alertCtrl: AlertController,
  private hs:HttpService,
  private as:AccountService,
  private appctl:App,
  private settings:Settings,
  public events:Events) {   

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad LoginPage');
  }
  login(){
    this.events.publish("begintest");
    this.as.LoginAction(this.disNo,this.pwd).then(_=>{
      this.settings.Set("disNo",this.disNo);   
      var _event=this.events;
      this.appctl.getRootNav().pop().then(_=>{
        _event.publish("user:login");
      });
    },_=>{
    let alert=this.alertCtrl.create({
      title:"登录信息",
      message:"用户名："+this.disNo+"\n\r 密码: "+this.pwd,
      buttons:["取消"]
    })
    alert.present();
    })
  }
  
}
